<?
function edit_record ($item_name,$code,$another_name,$nom_number,$sn_internal,$sub_rah, $data_open,$ed_code,$ed_type,$inv_numb,$count,$one_cost,$manage,$status,$auditory,$item_type,$comment,$edit=0) {
 include('db_connect.inc.php');
//echo $comment;
if(!$edit){

 
$sql="SELECT * FROM all_inventory where inv_numb='".$inv_numb."'";  
$process=mysql_query($sql, $db);
$row = mysql_fetch_array($process);
  $sql = "
  INSERT INTO all_inventory_log (item_name,code, another_name,nom_number,sn_internal,sub_rah, date_open, 
  ed_code, ed_type, inv_numb, count, one_cost, manage, status, auditory, item_type,
  item_name_new,code_new, another_name_new,nom_number_new,sn_internal_new,sub_rah_new, date_open_new, 
  ed_code_new, ed_type_new, inv_numb_new, count_new, one_cost_new, manage_new, status_new, auditory_new, item_type_new,date_change,user,comment)
	values ('".$row[item_name]."','".$row[code]."','".$row[another_name]."','".$row[nom_number]."','".$row[sn_internal]."','".$row[sub_rah]."',
	'".$row[date_open]."','".$row[ed_code]."','".$row[ed_type]."','".$row[inv_numb]."','".$row[count]."','".$row[one_cost]."',
	'".$row[manage]."','".$row[status]."','".$row[auditory]."','".$row[item_type]."',
	'".$item_name."', '".$code."', '".$another_name."', '".$nom_number."', '".$sn_internal."','".$sub_rah."', '".$data_open."', 
	'".$ed_code."','".$ed_type."',  '".$inv_numb."', '".$count."', '".$one_cost."', '".$manage."', 
	'".$status."', '".$auditory."','".$item_type."','".date('d.m.Y')."','".$_SESSION['user']."', '".$comment."')"; 
 $process = mysql_query($sql, $db);
$sql = "Delete from  all_inventory  where inv_numb='".$inv_numb."'"; 
} 
else{

//SELECT inv_numb,item_name,auditory, auditory_new,date_change,user FROM `all_inventory_log` where  auditory<>auditory_new
$sql="SELECT * FROM all_inventory where inv_numb='".$edit."'";  
$process=mysql_query($sql, $db);
$row = mysql_fetch_array($process);

  $sql = "
  INSERT INTO all_inventory_log (item_name,code, another_name,nom_number,sn_internal,sub_rah, date_open, 
  ed_code, ed_type, inv_numb, count, one_cost, manage, status, auditory, item_type,
  item_name_new,code_new, another_name_new,nom_number_new,sn_internal_new,sub_rah_new, date_open_new, 
  ed_code_new, ed_type_new, inv_numb_new, count_new, one_cost_new, manage_new, status_new, auditory_new, item_type_new,date_change,user,comment)
	values ('".$row[item_name]."','".$row[code]."','".$row[another_name]."','".$row[nom_number]."','".$row[sn_internal]."','".$row[sub_rah]."','".$row[date_open]."'
	,'".$row[ed_code]."','".$row[ed_type]."','".$row[inv_numb]."','".$row[count]."','".$row[one_cost]."',
	'".$row[manage]."','".$row[status]."','".$row[auditory]."','".$row[item_type]."',
	'".$item_name."', '".$code."', '".$another_name."', '".$nom_number."',
	'".$sn_internal."','".$sub_rah."', '".$data_open."', '".$ed_code."',
	'".$ed_type."',  '".$inv_numb."', '".$count."', '".$one_cost."',
	'".$manage."', '".$status."', '".$auditory."','".$item_type."',
	'".date('d.m.Y')."','".$_SESSION['user']."', '".$comment."')"; 
 $process = mysql_query($sql, $db);
 $sql = "
 Delete from  all_inventory  where inv_numb='".$edit."'"; 
}
 //echo $sql;
$process = mysql_query($sql, $db);
 $sql = "INSERT INTO all_inventory (item_name,code, another_name,nom_number,sn_internal,sub_rah, date_open, ed_code, ed_type, inv_numb, count, one_cost, manage, status, auditory, item_type)
 VALUES ('".$item_name."', '".$code."', '".$another_name."', '".$nom_number."','".$sn_internal."','".$sub_rah."', '".$data_open."', '".$ed_code."','".$ed_type."', '".$inv_numb."', '".$count."', '".$one_cost."', '".$manage."', '".$status."', '".$auditory."','".$item_type."')";
 $process = mysql_query($sql, $db);
// echo $sql;
//if (!$res){
//sql_error($sql);
//}

}


function sql_error($result){
echo "<font color=\"RED\"><b>Запрос: <br></font>";
echo $result;
echo "<br>";
echo"<font color=\"RED\"><b>Выполнился с ошибкой:</font><br>";
echo mysql_error();
echo "<br>";
}

?>

